//
//  LNHStepperView.m
//  LNH
//
//  Created by cruise on 2018/2/11.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "LNHStepperView.h"

#import "LNHGoodsDetailViewModel.h"

@interface LNHStepperView()

@property (nonatomic, strong) UIView *lineView;

@end

@implementation LNHStepperView

/**
 为视图绑定 viewModel
 
 @param viewModel 要绑定的ViewModel
 @param params 额外参数
 */
- (void)bindViewModel:(id <LMViewProtocol>)viewModel withParams:(NSDictionary *)params{
    if ([viewModel isKindOfClass:[LNHGoodsDetailViewModel class]]){
        
       
        
        
    }
    
}

/**
 初始化额外数据
 */
- (void)lm_initializeForView{
    
}

/**
 初始化视图
 */
- (void)lm_createViewForView{
    
    [self addSubview:self.lineView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.stepper];
    
    [self setNeedsUpdateConstraints];
}

-(void) updateConstraints {
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self);
        make.left.equalTo(self);
        make.right.equalTo(self);
        make.height.mas_equalTo(ONE_PIXEL);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(15);
        make.size.mas_equalTo(CGSizeMake(70, 20));
    }];
    
    [self.stepper mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-20);
        make.size.mas_equalTo(CGSizeMake(110, 30));
    }];
    
    [super updateConstraints];
}

#pragma mark - getter

-(UIView *) lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        [_lineView setBackgroundColor:[UIColor lightGrayColor]];
    }
    return _lineView;
}

-(UILabel *) titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        [_titleLabel setTextColor:RGBCOLOR(77,77,77)];
        [_titleLabel setFont:[UIFont systemFontOfSize:14]];
        [_titleLabel setText:@"购买数量"];
    }
    return _titleLabel;
}

-(PKYStepper *) stepper {
    if (!_stepper) {
        _stepper = [PKYStepper new];
        _stepper.minimum = 1;
        _stepper.maximum = 99999;
        _stepper.countLabel.textColor = [UIColor blackColor];
        _stepper.countLabel.font = FS(14);
        [_stepper.countLabel setBackgroundColor:RGBCOLOR(245, 245, 245)];
        [_stepper.countLabel.layer setBorderWidth:ONE_PIXEL];
        [_stepper.countLabel.layer setBorderColor:RGBCOLOR(229, 229, 229).CGColor];
        [_stepper setBorderWidth:ONE_PIXEL];
        [_stepper setBorderColor: RGBCOLOR(229, 229, 229)];
        
        [_stepper.decrementButton setTitleColor:RGBACOLOR(172, 172, 172,1) forState:UIControlStateNormal];
        [_stepper.incrementButton setTitleColor:RGBACOLOR(238, 128, 16,1) forState:UIControlStateNormal];
        [_stepper.decrementButton setBackgroundColor:RGBCOLOR(250, 250, 250)];
        [_stepper.incrementButton setBackgroundColor:RGBCOLOR(250, 250, 250)];
        
        [_stepper setButtonFont: FS(20)];
        [_stepper.countLabel setText:@"1"];
        _stepper.buttonWidth = 30*SCALE;
        [_stepper setValue:1];
    }
    return _stepper;
}

@end
